package net.zjitc.demo1.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.zjitc.demo1.dao.UDAO;
import net.zjitc.demo1.pojo.R;
import net.zjitc.demo1.pojo.RP;
import net.zjitc.demo1.pojo.User;
import net.zjitc.demo1.service.US;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class USimpl implements US {
    @Autowired
    private UDAO udao;
    @Override
    public RP<User> find(int pageCurrent, int pageSize, User user) {
        IPage page = new Page(pageCurrent,pageSize);
        LambdaQueryWrapper<User> wapper = new LambdaQueryWrapper<>();
        wapper.like(Strings.isNotEmpty(user.getUsername()),User::getUsername,user.getUsername());
        wapper.like(Strings.isNotEmpty(user.getGender()),User::getGender,user.getGender());
        wapper.like(Strings.isNotEmpty(user.getEmail()),User::getEmail,user.getEmail());
        udao.selectPage(page,wapper);
        return new RP<User>(page.getTotal(),page.getRecords());
    }

    @Override
    public boolean delete(Integer id) {
        return udao.deleteById(id)==1;
    }

    @Override
    public boolean update(User user) {
        return udao.updateById(user)==1;
    }

    @Override
    public boolean add(User user) {
        return udao.insert(user)==1;
    }
}
